package com.zxy.health.controller;

import com.zxy.health.dao.ReportDao;
import com.zxy.health.service.ReportService;
import com.zxy.health.utils.DateUtils;
import com.zxy.health.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/report")
public class ReportController {

    @Autowired
    ReportService reportService;

    @RequestMapping("/toReport")
    public String toReport() {
        return "report";
    }

    @RequestMapping("/addReport")
    @ResponseBody
    public boolean addReport(
            @RequestParam("title") String title,
            @RequestParam("message") String message,
            @RequestParam("suzhounum") long suzhounum,
            @RequestParam("jiangsunum") long jiangsunum,
            @RequestParam("allnum") long allnum
    ) {
        ReportDao reportDao = new ReportDao(StringUtils.getSimpleUUID(),
                title, message, new Date().getTime(),
                suzhounum, jiangsunum, allnum);
        if (reportService.addReport(reportDao)) {
            return true;
        } else {
            return false;

        }
    }

    @RequestMapping("/getReport")
    @ResponseBody
    public ReportDao getReport() {
        return reportService.getReport();
    }
}
